package com.deyou.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.deyou.Constants;
import com.deyou.R;
import com.deyou.model.HomePageCityBean;
import com.deyou.model.OrderBean;
import com.deyou.util.DateUtil;
import com.deyou.util.GlideImageLoader;
import com.deyou.util.Urls;
import com.deyou.widget.CircleImageView;
import com.zhy.autolayout.utils.AutoUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yangyuancheng on 2017/6/14.
 */

public class OrderItemAdapter extends BaseQuickAdapter<OrderBean.OrderDetail, OrderItemAdapter.ViewHolder> {

    private Context mContext;

    public OrderItemAdapter(Context context) {
        super(R.layout.my_travel_item_layout);
        this.mContext = context;
    }

    @Override
    protected void convert(ViewHolder helper, OrderBean.OrderDetail item) {
        if (item.orderStatus == 0){
            helper.dealTravelLayout.setVisibility(View.VISIBLE);
            helper.btnCancelTravel.setVisibility(View.GONE);
            helper.btnPayTravel.setVisibility(View.GONE);
            helper.btnCommentTravel.setVisibility(View.VISIBLE);
            helper.btnCommentTravel.setText("去确认");
            helper.tvTravelStatus.setText("待确认");
        } else if (item.orderStatus == 1){
            helper.dealTravelLayout.setVisibility(View.GONE);
            helper.tvTravelStatus.setText("待付款");
        } else if (item.orderStatus == 2){
            helper.dealTravelLayout.setVisibility(View.GONE);
            helper.tvTravelStatus.setText("待入住");
        } else if (item.orderStatus == 3){
            helper.dealTravelLayout.setVisibility(View.GONE);
            helper.tvTravelStatus.setText("待评价");
        } else {
            helper.dealTravelLayout.setVisibility(View.GONE);
            helper.tvTravelStatus.setText("已完成");
        }

        if (!TextUtils.isEmpty(item.userPic))
            new GlideImageLoader().displayImage(mContext, Urls.UserImageBaseUrl + item.userPic, helper.imgOwnerPhoto);
        else
            new GlideImageLoader().displayImage(mContext, R.drawable.ic_default_avatar2 , helper.imgOwnerPhoto);
//        if (!TextUtils.isEmpty(item.userPic))
//            new GlideImageLoader().displayImage(mContext, Urls.UserImageBaseUrl + item.userPic, helper.imgOwnerPhoto);
//        else
//            new GlideImageLoader().displayImage(mContext, R.drawable.ic_default_avatar2 , helper.imgOwnerPhoto);

        helper.tvOwnerName.setText("房主：" + item.userNickname);
        helper.tvHomestayName.setText(item.resourceAddress);
        helper.tvCheckinInfo.setText(item.resourceType + " 一共" + item.checknum + "人入住");
        String checkInDate = "";
        String checkOutDate = "";
        if (!TextUtils.isEmpty(item.checkindate))
            checkInDate = DateUtil.getMonthAndDay1(item.checkindate);
        else
            checkInDate = "";
        if (!TextUtils.isEmpty(item.checkoutdate))
            checkOutDate = DateUtil.getMonthAndDay1(item.checkoutdate);
        else
            checkOutDate = "";
        helper.tvRentTime.setText(checkInDate + "-" + checkOutDate + " 共" + item.nightsNum + "晚");
        helper.tvTotalMoney.setText("总价：" + Constants.RMB_UNIT + item.orderAmount);
        helper.addOnClickListener(R.id.btn_cancel_travel).addOnClickListener(R.id.btn_pay_travel).addOnClickListener(R.id.btn_comment_travel);
    }

    static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.img_owner_photo)
        CircleImageView imgOwnerPhoto;
        @BindView(R.id.tv_owner_name)
        TextView tvOwnerName;
        @BindView(R.id.tv_travel_status)
        TextView tvTravelStatus;
        @BindView(R.id.img_homestay)
        ImageView imgHomestay;
        @BindView(R.id.tv_homestay_name)
        TextView tvHomestayName;
        @BindView(R.id.tv_checkin_info)
        TextView tvCheckinInfo;
        @BindView(R.id.tv_rent_time)
        TextView tvRentTime;
        @BindView(R.id.tv_total_money)
        TextView tvTotalMoney;
        @BindView(R.id.btn_cancel_travel)
        TextView btnCancelTravel;
        @BindView(R.id.btn_pay_travel)
        TextView btnPayTravel;
        @BindView(R.id.btn_comment_travel)
        TextView btnCommentTravel;
        @BindView(R.id.deal_travel_layout)
        LinearLayout dealTravelLayout;

        ViewHolder(View view) {
            super(view);
            AutoUtils.auto(view);
            ButterKnife.bind(this, view);
        }
    }
}
